Helpful Information
 
 
Category: Perl CGI and DBI, MySQL, DBI
Perl CGI and DBI, MySQL, DBI->connect

Hi,

I have posted this message on the CGI/perl scripts forum as well. But perhaps it has more to do with MySQL, so I am posting it here as well. Hope that is ok.

I am using Perl v. 5.10 and MySQL v.5.1.31 Community Server (GPL), Apache Server 2.2 on Windows XP Professional Service Pack 3

Given this 8 line segment of code from a Perl CGI script:
my $db = "gfr";
my $un = "gfr";
my $pw = "gfr";
my $dbH = "";
$dbH = DBI->connect("DBI:ODBC:$db",$un,$pw) ||
die "Got error when connecting to un=$un, pw=$pw, db=$db\n".DBI->errstr;
print "xxx";
exit;

It executes perfectly when I run it from a command window.
i.e. perl -w prgNm.cgi


When I call the script from an HTML file like this:
<p style="text-indent:5cm">
<a href=http://localhost/gfr-bin/prgNm.cgi>Load new image filenames</a>
</p>
I get the error:
Got error when connecting to un=gfr, pw=gfr, db=gfr
[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified (SQL-IM002) at C:/Documents/Documents_20090101_to_20091231/Computing/GalleryForRent_Maintenance/gfr-bin/prgNm.cgi line 49.

If I comment out the two lines:
# $dbH = DBI->connect("DBI:ODBC:$db",$un,$pw) ||
# die "Got error when connecting to un=$un, pw=$pw, db=$db\n".DBI->errstr;
I get the expected "xxx" in the web browser (so I know that it does not lie with the Apache Server's httpd.conf file).

Would anyone have any ideas?

Thanks,
Andynic
PS: To try to avoid using ODBC, I have tried to obtaiin a DBD-mysql module for Perl 5.10 and MySQL v5.1 but nothing I have found on the web works nor anything I have received from the MySQL forums.










privacy (GDPR)